function AttBmHz() {
    this.form = this.InitForm();
    //this.table=this.InitTable();
    //this.table=this.InitTableByBt();
    //this.InitGrid();
    this.orgsuytable = this.InitOrgSuyTable();
    this.tab = this.InitTab();
    this.table = null;

    $("#year").val($("#hidyear").val());
    $("#month").val($("#hidmonth").val());
    this.form.render('select');

    $("#bottom_btns").hide();
    $('#pdfbutton').hide()

}

AttBmHz.prototype.InitTab = function () {
    var element;
    layui.use('element', function () {
        element = layui.element;

        element.on('tab(tabcontent)', function (data) {
            if (data.index == 1) {
                $("#bottom_btns").show();
                if ($("#hidstatus").val() != '') {
                    var status = Number($("#hidstatus").val());
                    if (status > 0) {
                        $("#btnbmtj").attr("disabled", "disabled");
                        $("#btnbmtj").html("该部门已提交");
                    }
                }
            } else {
                console.log("nodata");
                $("#hidorgid").val(0);
                $("#hidorgsummaryid").val(0);
                $("#hidstatus").val('');
                $("#bottom_btns").hide();
                $("#btnbmtj").removeAttr("disabled");

                $("#realname").val("");
            }
        });

    });
    return element;
}

AttBmHz.prototype.OpTab = function (tabindex, obj) {
    this.tab.tabChange('tabcontent', tabindex);
}

AttBmHz.prototype.InitForm = function () {
    var form;
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.on('select(year)', function (data) {
            $("#hidyear").val(data.value);
            form.render('select');

            vAttBmHz.searchtableorgsuy();
        });
        form.on('select(month)', function (data) {
            $("#hidmonth").val(data.value);
            form.render('select');
            vAttBmHz.searchtableorgsuy();
        });

        form.render();
    });
    return form;
}

AttBmHz.prototype.InitGrid = function () {
    var _this = this;
    window.liger.remove("orgsuylist");
    if (_this.grid == null) {
        _this.grid = $("#orgsuylist").ligerGrid({
            columns: [{display: '序号', width: 80, name: 'rowNum'},
                {display: '机构名称', width: 250, align: 'left', name: 'orgname', id: "orgname"},
                {display: '年', width: 100, name: 'year'},
                {
                    display: '季度', width: 100, name: 'quarter', render: function (rowdata, rowindex, value) {
                        var month = rowdata.month;
                        var quarter = rowdata.quarter;
                        var str = '';
                        switch (quarter) {
                            case null:
                            case '':
                            case undefined:
                                if (month == "1" || month == "2" || month == "3") {
                                    str = "第一季度";
                                }
                                if (month == "4" || month == "5" || month == "6") {
                                    str = "第二季度";
                                }
                                if (month == 7 || month == 8 || month == 9) {
                                    str = "第三季度";
                                }
                                if (month == 10 || month == 11 || month == 12) {
                                    str = "第四季度";
                                }
                                break;
                            case 1:
                                str = "第一季度";
                                break;
                            case 2:
                                str = "第二季度";
                                break;
                            case 3:
                                str = "第三季度";
                                break;
                            case 4:
                                str = "第四季度";
                                break;
                        }
                        return str;
                    }
                },
                {display: '月份', width: 100, name: 'month'},
                {
                    display: '状态', width: 120, name: 'status', render: function (rowdata, rowindex, value) {
                        var status = rowdata.status;
                        if (!rowdata.usercount || rowdata.usercount <= 1) {
                            return '';
                        }
                        var str = '';
                        switch (status) {
                            case null:
                            case '':
                            case undefined:
                                str = "未填报";
                                break;
                            case 0:
                                str = '<span class="tbcolor">填报<span>';
                                break;
                            case 1:
                                str = "提交";
                                break;
                            case 2:
                                str = "归档";
                                break;
                            case 3:
                                str = "驳回";
                                break;

                        }
                        return str;
                    }
                },
                {
                    display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                        var html = '';
                        alert(rowdata.iscreate);
                        if (rowdata.status != null && rowdata.iscreate == 1) {
                            html += '<img class="btn-img" src="' + ctxStatic + '/images/button/detail.png" lay-event="detail" onclick="vAttBmHz.getattdetail(' + rowdata.orgid + ',' + rowdata.orgsummaryid + ',' + rowdata.status + ',\'' + rowdata.orgname + '\',' + rowdata.year + ',' + rowdata.month + ')" alt="详情" title="详情">';
                        }
                        if (rowdata.status == null && rowdata.iscreate == 1) {
                            html += ' <img class="btn-img" src="' + ctxStatic + '/images/index/yaosu.png" lay-event="shengcheng" onclick="vAttBmHz.createatttb(' + rowdata.orgid + ')" alt="生成考勤" title="生成考勤">';
                        }
                        if ((rowdata.status == "0" || rowdata.status == "3") && rowdata.iscreate == 1) {
                            html += '<img class="btn-img" src="' + ctxStatic + '/images/button/tijiao.png" lay-event="tijiao" alt="提交" onclick="vAttBmHz.updatestatus(' + rowdata.orgsummaryid + ',1)" title="提交">';
                        }
                        return html;
                    }
                }
            ],
            pageSize: 30,
            url: "get_org_summary_list_grid" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: $("#hidyear").val(),
                month: $("#hidmonth").val()
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight: 28,
            onSuccess: function (rowdata, rowindex) {
                if (rowdata.status > 0) {
                    alert(rowdata.msg)
                }
            },
            alternatingRow: true,
            border: 0,
            usePager: false,
            tree: {
                columnId: "orgname",
                idField: "orgid",
                parentIDField: "orgparentid"

            }
        })
    }
}

AttBmHz.prototype.searchlist = function () {
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: $("#hidyear").val(),
            month: $("#hidmonth").val()
        }
    });
    this.grid.loadData();
}

AttBmHz.prototype.InitOrgSuyTable = function () {
    var table;
    var _this = this;
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#orgsuylist'
            , height: $(window).height() - 140
            , url: 'get_org_summary_list' // 数据接口
            , page: true // 开启分页
            , limit: 30
            , id: 'orgsuylist'
            , method: "post"
            , cols: [[ // 表头
                {type: 'numbers'}
                //{field : 'rowNum',title : '序号',width : 70,align : 'center'}
                , {field: 'orgname', title: '单位名称', width: 250, align: 'center'}
                , {field: 'year', title: '年', width: 100, align: 'center'}
                , {field: 'quarter', title: '季度', width: 100, align: 'center'}
                , {field: 'month', title: '月份', width: 100, align: 'center'}
                , {field: 'orgsummaryid', title: '部门人数', width: 100, align: 'center'}
                , {field: 'status', title: '状态', width: 120, align: 'center'}
                , {title: '操作', width: 100, align: 'left', toolbar: '#operateorgsuy'}
            ]]
            , request: {
                type: 'post'
            }
            , page: false
            , where: {
                year: $("#hidyear").val(),
                month: $("#hidmonth").val()
            }
            , even: true //开启隔行背景
            , done: function (res, page, count) {
                var dataarr = res.data;


                $("[data-field='orgsummaryid']").children().each(function (index) {
                    if (index > 0) {
                        var thisdata = dataarr[index - 1];
                        var text = $(this).text();
                        if (text == null || text == '') {
                            var percount = thisdata.usercount;
                            $(this).text(percount);
                        } else {
                            var realusercount = thisdata.realusercount;
                            $(this).text(realusercount);
                        }
                    }
                })
                $("[data-field='status']").children().each(function (index) {
                    if (index > 0) {
                        var text = $(this).text();
                        var prev = $(this).parent().prev();
                        if (prev.text() == '' || prev.text() <= 1) {
                            text = '9';
                        }
                        switch (text) {
                            case null:
                                $(this).text("未填报");
                                break;
                            case '':
                                $(this).text("未填报");
                                break;
                            case '0':
                                $(this).text("填报");
                                break;
                            case '1':
                                $(this).text("提交");
                                break;
                            case '2':
                                $(this).text("归档");
                                break;
                            case '3':
                                $(this).text("驳回");
                                break;
                            case '4':
                                $(this).text("审核通过");
                                break;
                            default :
                                $(this).text('')
                                break;
                        }
                    }
                })
                $("[data-field='quarter']").children().each(function (index) {
                    if (index > 0) {
                        var text = $(this).text();
                        switch (text) {
                            case null:
                            case '':
                                var month = dataarr[index - 1].month;
                                if (month == 1 || month == 2 || month == 3) {
                                    $(this).text("第一季度");
                                }
                                if (month == 4 || month == 5 || month == 6) {
                                    $(this).text("第二季度");
                                }
                                if (month == 7 || month == 8 || month == 9) {
                                    $(this).text("第三季度");
                                }
                                if (month == 10 || month == 11 || month == 12) {
                                    $(this).text("第四季度");
                                }
                                break;
                            case '1':
                                $(this).text("第一季度");
                                break;
                            case '2':
                                $(this).text("第二季度");
                                break;
                            case '3':
                                $(this).text("第三季度");
                                break;
                            case '4':
                                $(this).text("第四季度");
                                break;
                        }
                    }
                })

            }

        });


        //监听工具条
        table.on('tool(orgsuylist)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                $("#hidorgid").val(data.orgid);
                $("#hidorgsummaryid").val(data.orgsummaryid);
                $("#hidstatus").val(data.status);
                _this.OpTab(2, data);

                $("#table_title").html(data.orgname + " " + data.year + " 年  " + data.month + " 月考勤表");
                if (data.status == '2' || data.status == '4') {
                    // 不显示了
                    // console.log("show");
                    // $('#pdfbutton').show();
                } else {
                    $('#pdfbutton').hide();
                }
                _this.table = _this.InitTableByBt(data.orgid, data.orgsummaryid, data.status);
                _this.testData(data.orgid, data.orgsummaryid, data.status, "", "");

            } else if (obj.event === 'tijiao') {
                vAttBmHz.updatestatus(data.orgsummaryid, 1);
            } else if (obj.event === 'shengcheng') {
                vAttBmHz.createatttb(data.orgid, data.year, data.month);
            }
        });


    });

    return table;
}


AttBmHz.prototype.getattdetail = function (orgid, orgsummaryid, status, orgname, year, month) {
    $("#hidorgid").val(orgid);
    $("#hidorgsummaryid").val(orgsummaryid);
    $("#hidstatus").val(status);
    this.OpTab(2);

    $("#table_title").html(orgname + " " + year + " 年  " + month + " 月考勤表");

    this.table = this.InitTableByBt(orgid, orgsummaryid, "");
    this.testData(orgid, orgsummaryid, "", "", "");
}

AttBmHz.prototype.querydetail = function () {
    if ($("#hidorgid").val() == "" || $("#hidorgid").val() == "0") {
        top.mylayui.msg('请先点机构列表后面详情按钮，再点击查询', {icon: 0});
        return;
    }


    this.InitTableByBt($("#hidorgid").val(), $("#hidorgsummaryid").val(), "");
    this.testData($("#hidorgid").val(), $("#hidorgsummaryid").val(), "", "", "");
}

AttBmHz.prototype.InitTableByBt = function (orgid, orgsummaryid, status) {
    var table;
    var _this = this;
    if (_this.table != null) {
        _this.table.reload('attbmhzlist', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            , where: {
                //year: $("#detailyear").val(),
                //mouth:$("#detailmonth").val(),
                year: '',
                mouth: '',
                orgid: orgid,
                orgsummaryid: orgsummaryid,
                realname: $("#realname").val(),
                status: status
            }
        });
    }
    else {

        layui.use('table', function () {
            table = layui.table;
            table.init('attbmhzlist', {
                height: $(window).height() - 210
                , url: 'get_list' // 数据接口
                , page: true // 开启分页
                , limit: 40
                , id: 'attbmhzlist'
                , limits: [20, 40, 80, 100]
                , method: "post"
                , request: {
                    type: 'post'
                }
                , where: {
                    //year: $("#detailyear").val(),
                    //mouth:$("#detailmonth").val(),
                    year: '',
                    mouth: '',
                    orgid: orgid,
                    orgsummaryid: orgsummaryid,
                    realname: $("#realname").val(),
                    status: status

                }
                , done: function (res, page, count) {

                    var dataarr = res.data;
                    if (dataarr.length != 0) {
                        console.log(dataarr[0]);
                        $("#hidusername").val(dataarr[0].appusername);
                        $("#hidorgname").val(dataarr[0].szdwname);
                    }

                    $("[data-field='status']").children().each(function (index) {
                        if (index > 0) {
                            var text = $(this).text();

                            switch (text) {
                                case null:
                                    $(this).text("未填报");
                                    break;
                                case '':
                                    $(this).text("未填报");
                                    break;
                                case '0':
                                    $(this).text("填报");
                                    break;
                                case '1':
                                    $(this).text("提交");
                                    break;
                                case '2':
                                    $(this).text("归档");
                                    break;
                                case '3':
                                    $(this).text("驳回");
                                    break;
                            }
                        }
                    })


                    $("[data-field='sfqq']").children().each(function (index) {
                        if (index > 0) {
                            var text = $(this).text();
                            if (text == "0") {
                                $(this).text("否");
                            }
                            else {
                                $(this).text("是");
                            }
                        }
                    })
                }
            });


            //监听工具条
            table.on('tool(attbmhzlist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    vAttBmHz.openadddetail(obj.data.attsummaryid, obj.data.orgsummaryid);
                } else if (obj.event === 'del') {

                    top.mylayui.confirm('确定要删除吗？', {icon: 0}, function (index, dd) {
                        top.mylayui.close(index);
                        vUser.deleteentity(data.userid);
                    });
                } else if (obj.event === 'edit') {
                    //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                    //_this.OpTab(2,data);
                    //vUser.openadd(obj.data.userid);
                }
                else if (obj.event === 'btntz') {
                    vAttBmHz.openadd(obj.data.attsummaryid, obj.data.orgsummaryid, obj.data.userid);
                }
            });


        })
    }
    return table;
}

AttBmHz.prototype.testData = function (orgid, orgsummaryid, status, year, month) {
    console.log(orgsummaryid);
    $.ajax({
        type: "POST",
        url: "get_list",
        data: {
            year: year,
            mouth: month,
            orgid: orgid,
            orgsummaryid: orgsummaryid,
            realname: $("#realname").val(),
            status: status,
            page: 1,
            limit: 1000
        },
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')').data;
            for (var i = 0; i < data.length; i++) {


                var tr = "<tr><td>" + (i + 1) + "</td>";
                tr += "<td>" + data[i].realname + "</td>";

                tr += "<td>" + data[i].cardno + "</td>";
                tr += "<td>" + data[i].orgname + "</td>";
                tr += "<td>" + (data[i].rsgxorgname == null ? '' : data[i].rsgxorgname) + "</td>";
                tr += "<td>" + data[i].year + "</td>";
                tr += "<td>" + data[i].mouth + "</td>";
                tr += "<td>" + (data[i].sfjb == 0 ? '否' : '是') + "</td>";
                tr += "<td>" + data[i].wcqtsxj + "</td>";
                tr += "<td>" + data[i].xjts + "</td>";
                tr += "<td>" + data[i].tqjts + "</td>";
                tr += "<td>" + data[i].hjts + "</td>";
                tr += "<td>" + data[i].syjts + "</td>";
                tr += "<td>" + data[i].sangjts + "</td>";
                tr += "<td>" + data[i].gsts + "</td>";
                tr += "<td>" + data[i].bjts + "</td>";
                tr += "<td>" + data[i].sjts + "</td>";
                tr += "<td>" + data[i].qtts + "</td>";
                tr += "<td>" + data[i].cdcc + "</td>";
                tr += "<td>" + data[i].ztcc + "</td>";
                tr += "<td>" + data[i].kgcs + "</td>";
                tr += "<td>" + (data[i].remark == null ? '' : data[i].remark) + "</td></tr>";


                $('#tableData').append(tr);
            }

        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}

AttBmHz.prototype.openadd = function (attsummaryid, orgsummaryid, userid) {
    top.mylayui.open({
        type: 2,
        title: '调整考勤',
        shadeClose: true,
        shade: 0.5,
        area: ['800px', '450px'],
        content: 'attbmhz/att_bm_hz_edit_nodetail?attsummaryid=' + attsummaryid + "&orgsummaryid=" + orgsummaryid + "&userid=" + userid
    });

}

AttBmHz.prototype.openadddetail = function (attsummaryid, orgsummaryid) {
    top.mylayui.open({
        type: 2,
        title: '考勤详情',
        shadeClose: true,
        shade: 0.5,
        area: ['1000px', '500px'],
        content: 'attbmhz/att_bm_hz_show?attsummaryid=' + attsummaryid + "&orgsummaryid=" + orgsummaryid
    });
    var iframeele = top.$(".layui-layer-content").find('iframe');
    iframeele.css({"height": $(iframeele).height() - 10});
}

AttBmHz.prototype.addresult = function (result, msg) {
    if (result > 0) {
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        vAttBmHz.searchtable();
    }
    else {
        if (msg) {
            top.mylayui.msg(msg, {icon: 0});
        } else {
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}

AttBmHz.prototype.searchtable = function () {
    this.table.reload('attbmhzlist', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        , where: {
            year: $("#year").val(),
            mouth: $("#month").val()
        }
    });
    _this.testdata($("#hidorgid").val(), $("#hidorgsummaryid").val(), "", $("#year").val(), $("#month").val());
}


AttBmHz.prototype.exportexcel = function () {
    if ($("#hidorgid").val() == "" || $("#hidorgid").val() == "0") {
        top.mylayui.msg('请先点机构列表后面详情按钮，再点击导出', {icon: 0});
        return;
    }
    top.ShowZheZhao();
    $.ajax({
        type: "POST",
        url: "export_excel",
        data: {
            year: '',
            mouth: '',
            orgid: $("#hidorgid").val(),
            orgsummaryid: $("#hidorgsummaryid").val()
        },
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                //top.mylayui.msg(data.msg, {icon: 1});
                //alert(data.msg);
                window.open(data.msg, '_self');
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();

        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}


AttBmHz.prototype.searchtableorgsuy = function () {
    this.orgsuytable.reload('orgsuylist', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        , page: false
        , where: {
            year: $("#hidyear").val(),
            month: $("#hidmonth").val()
        }
    });
}

AttBmHz.prototype.createatttb = function (orgid, year, month) {

    top.ShowZheZhao();
    $.ajax({
        type: "POST",
        //url:"create_atttb",
        url: "create_atttb_nodetail",
        data: {orgid: orgid, year: year, month: month},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                top.mylayui.msg(data.msg, {icon: 1});
                //vAttBmHz.searchtableorgsuy();
                vAttBmHz.searchtableorgsuy();
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}

AttBmHz.prototype.updatestatus = function (orgsummaryid, status) {
    top.mylayui.confirm('点击提交后，考勤会提交到部门领导进行审批', {icon: 0}, function (index, dd) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "update_attstatus",
            data: {orgsummaryid: orgsummaryid, status: status},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                    //vAttBmHz.searchtableorgsuy();
                    vAttBmHz.searchtableorgsuy();
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    })
}

AttBmHz.prototype.btntijiao = function () {
    var orgsummaryid = $("#hidorgsummaryid").val();
    vAttBmHz.updatestatus(orgsummaryid, 1);
}

AttBmHz.prototype.pdfok = function () {
    var html = "房山公安分局" + $('#hidorgname').val() + "单位";
    var month = $("#month").val();
    var year = $("#year").val();
    html += year + "年" + month + "月考勤"
    $('.orgname').html(html)

    if ($("#hidorgid").val() == "" || $("#hidorgid").val() == "0") {
        top.mylayui.msg('请先点机构列表后面详情按钮，再点击生成', {icon: 0});
        return;
    }
    var userName = $("#hidusername").val();
    var orgid = $("#hidorgid").val();
    var year = $("#year").val();
    var month = $("#month").val();

    var date = new Date();
    var nowtime = $("#year").val() + "年" + date.getMonth() + 1 + "月" + date.getDate() + "日";
    watermark({watermark_txt: userName + "  " + nowtime});

    var targetDom = $("#table");
    //把需要导出的pdf内容clone一份，这样对它进行转换、微调等操作时才不会影响原来界面
    var copyDom = targetDom.clone();
    //新的div宽高跟原来一样，高度设置成自适应，这样才能完整显示节点中的所有内容（比如说表格滚动条中的内容）
    copyDom.width(targetDom.width() + "px");
    copyDom.height(targetDom.height() + "px");
    copyDom.css('display', 'block');
    copyDom.css({
        "background-color": "white",
        "position": "absolute",
        "top": "600px",
        "z-index": "-1",
        "height": targetDom.height()
    });
    $('body').append(copyDom);
    svg2canvas(copyDom);
    html2canvas(copyDom, {
        onrendered: function (canvas) {
            var imgData = canvas.toDataURL('image/jpeg');
            var img = new Image();
            img.src = imgData;

            // img.src = 'http://127.0.0.1:8080/1.pdf';
            //根据图片的尺寸设置pdf的规格，要在图片加载成功时执行，之所以要*0.225是因为比例问题
            img.onload = function () {
                //此处需要注意，pdf横置和竖置两个属性，需要根据宽高的比例来调整，不然会出现显示不完全的问题
                if (this.width > this.height) {
                    var doc = new jsPDF('l', 'mm', [this.width * 0.225,
                        this.height * 0.225
                    ]);
                } else {
                    var doc = new jsPDF('p', 'mm', [this.width * 0.225,
                        this.height * 0.225
                    ]);
                }
                doc.addImage(imgData, 'jpeg', 0, 0, this.width * 0.225,
                    this.height * 0.225);

                top.ShowZheZhao();
                //根据下载保存成不同的文件名
                if (year != null && year != "") {
                    $.ajax({
                        type: "POST",
                        url: "createPDF",
                        data: {
                            file: doc.output("datauristring"),
                            year: year,
                            month: month,
                            orgid: orgid
                        },
                        beforeSend: function (XHR) {

                        },
                        success: function (data) {


                        },
                        complete: function (XHR) {
                            top.ShowZheZhao();
                        },
                        error: function () {
                            top.ShowZheZhao();
                        }
                    });
                }


                console.log(doc.output("datauristring"))
                // doc.save('pdf_' + new Date().getTime() + '.pdf');
            };
            //删除复制出来的div
            copyDom.remove();
        },
        background: "#fff",

        //这里给生成的图片默认背景，不然的话，如果你的html根节点没设置背景的话，会用黑色填充。
        allowTaint: true //避免一些不识别的图片干扰，默认为false，遇到不识别的图片干扰则会停止处理html2canvas
    });
}

function watermark(settings) {
    //默认设置
    var defaultSettings = {
        watermark_txt: "text",
        watermark_x: 20,//水印起始位置x轴坐标
        watermark_y: 20,//水印起始位置Y轴坐标
        watermark_rows: 0,//水印行数
        watermark_cols: 20,//水印列数
        watermark_x_space: 100,//水印x轴间隔
        watermark_y_space: 50,//水印y轴间隔
        watermark_color: '#aaa',//水印字体颜色
        watermark_alpha: 0.6,//水印透明度
        watermark_fontsize: '15px',//水印字体大小
        watermark_font: '微软雅黑',//水印字体
        watermark_width: 210,//水印宽度
        watermark_height: 80,//水印长度
        watermark_angle: 15//水印倾斜度数
    };
    //采用配置项替换默认值，作用类似jquery.extend
    if (arguments.length === 1 && typeof arguments[0] === "object") {
        var src = arguments[0] || {};
        for (key in src) {
            if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key])
                continue;
            else if (src[key])
                defaultSettings[key] = src[key];
        }
    }

    var oTemp = document.createDocumentFragment();

    //获取页面最大宽度
    var page_width = Math.max(document.body.scrollWidth, document.body.clientWidth);
    var cutWidth = page_width * 0.0150;
    var page_width = page_width - cutWidth;
    //获取页面最大高度
    var targetDom = $("#table");
    var hidtablehight= targetDom.height();
    var page_height = parseInt(hidtablehight);
    // var page_height = document.body.scrollHeight+document.body.scrollTop;
    //如果将水印列数设置为0，或水印列数设置过大，超过页面最大宽度，则重新计算水印列数和水印x轴间隔
    if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings.watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space * (defaultSettings.watermark_cols - 1)) > page_width)) {
        defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings.watermark_x_space) / (defaultSettings.watermark_width + defaultSettings.watermark_x_space));
        defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x - defaultSettings.watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
    }
    //如果将水印行数设置为0，或水印行数设置过大，超过页面最大长度，则重新计算水印行数和水印y轴间隔
    if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings.watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (defaultSettings.watermark_rows - 1)) > page_height)) {
        defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height - defaultSettings.watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
        defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) - defaultSettings.watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
    }
    var x;
    var y;
    for (var i = 0; i < defaultSettings.watermark_rows; i++) {
        y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
        for (var j = 0; j < defaultSettings.watermark_cols; j++) {
            x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;

            var mask_div = document.createElement('div');
            mask_div.id = 'mask_div' + i + j;
            mask_div.className = 'mask_div';
            mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
            //设置水印div倾斜显示
            mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
            mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
            mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
            mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
            mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
            mask_div.style.visibility = "";
            mask_div.style.position = "absolute";
            mask_div.style.left = x + 'px';
            mask_div.style.top = y + 'px';
            mask_div.style.overflow = "hidden";
            mask_div.style.zIndex = "9999";
            mask_div.style.pointerEvents = 'none';//pointer-events:none  让水印不遮挡页面的点击事件
            //mask_div.style.border="solid #eee 1px";
            mask_div.style.opacity = defaultSettings.watermark_alpha;
            mask_div.style.fontSize = defaultSettings.watermark_fontsize;
            mask_div.style.fontFamily = defaultSettings.watermark_font;
            mask_div.style.color = defaultSettings.watermark_color;
            mask_div.style.textAlign = "center";
            mask_div.style.width = defaultSettings.watermark_width + 'px';
            mask_div.style.height = defaultSettings.watermark_height + 'px';
            mask_div.style.display = "block";
            oTemp.appendChild(mask_div);
        }
        ;
    }
    ;
    // $("#table").appendChild(oTemp);
    document.getElementById("table").appendChild(oTemp);
}

function svg2canvas(targetElem) {
    var svgElem = targetElem.find('svg');
    svgElem.each(function (index, node) {
        var parentNode = node.parentNode;
        //由于现在的IE不支持直接对svg标签node取内容，所以需要在当前标签外面套一层div，通过外层div的innerHTML属性来获取
        var tempNode = document.createElement('div');
        tempNode.appendChild(node);
        var svg = tempNode.innerHTML;
        var canvas = document.createElement('canvas');
        //转换
        canvg(canvas, svg);
        parentNode.appendChild(canvas);
    });
}

var vAttBmHz = null;
$(function () {
    vAttBmHz = new AttBmHz();
})